package org.magicsoft.office.excel.model;

import java.util.List;

import org.magicsoft.office.exception.ModelException;

public class TargetTable {

	private String displayName = null;

	private String tableName = null;

	private String alias = null;

	private PrimaryKey primaryKey = null;

	private String oidColumn = null;

	private String nidColumn = null;

	private int oidParameterIndex = -1;

	private int nidParameterIndex = -1;

	private String[] updateByColumns = null;

	private List<DefaultValue> defaultValues = null;

	private List<UniqueKey> uniqueKeys = null;

	private boolean junctionTable = false;

	public TargetTable(String tableName) {
		this(tableName, tableName);
		if (tableName.length() > 20) {
			throw new ModelException("目标表：“" + tableName + "”名称过长，请指定别名，长度不能超过20。");
		}
	}

	public TargetTable(String tableName, String alias) {
		this.tableName = tableName;
		this.alias = alias;
	}

	public String getDisplayName() {
		if (this.displayName == null) {
			this.displayName = this.tableName;
		}
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public TargetTable setPrimaryKey(PrimaryKey primaryKey) {
		this.primaryKey = primaryKey;
		return this;
	}

	public TargetTable updateByColumn(String... updateByColumns) {
		this.updateByColumns = updateByColumns;
		return this;
	}

	public List<UniqueKey> getUniqueKeys() {
		return uniqueKeys;
	}

	public TargetTable setUniqueKeys(List<UniqueKey> uniqueKeys) {
		this.uniqueKeys = uniqueKeys;
		return this;
	}

	public boolean isJunctionTable() {
		return junctionTable;
	}

	public TargetTable setJunctionTable(boolean junctionTable) {
		this.junctionTable = junctionTable;
		return this;
	}

	public String[] getUpdateByColumns() {
		return this.updateByColumns;
	}

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getAlias() {
		return alias;
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	public PrimaryKey getPrimaryKey() {
		return primaryKey;
	}

	public int getOidParameterIndex() {
		return oidParameterIndex;
	}

	public void setOidParameterIndex(int oidParameterIndex) {
		this.oidParameterIndex = oidParameterIndex;
	}

	public String getOidColumn() {
		if (this.oidColumn == null) {
			this.oidColumn = this.getAlias() + "_oid_";
		}
		return this.oidColumn;
	}

	public String getNidColumn() {
		if (this.nidColumn == null) {
			this.nidColumn = this.getAlias() + "_nid_";
		}
		return this.nidColumn;
	}

	public int getNidParameterIndex() {
		return nidParameterIndex;
	}

	public void setNidParameterIndex(int nidParameterIndex) {
		this.nidParameterIndex = nidParameterIndex;
	}

	public List<DefaultValue> getDefaultValues() {
		return defaultValues;
	}

	public TargetTable setDefaultValues(List<DefaultValue> defaultValues) {
		this.defaultValues = defaultValues;
		return this;
	}

}
